{% extends 'layout.html' %}

{% block title %}{{ dbName }}{% endblock %}

{% block breadcrumb %}
  <li>
    <a href="{{ dbUrl }}">Database:</a>
  </li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ dbName }}<span class="caret"></span></a>
    <ul class="dropdown-menu">
      {% for db in databases %}
      <li><a href="{{ baseHref }}db/{{ db | url_encode }}/">{{ db }}</a></li>
      {% endfor %}
    </ul>
  </li>
{% endblock %}

{% block content %}
<div class="panel panel-default">
  <div class="panel-heading">
    <div style="display: inline-block;">
    <h4 style="font-weight: bold;">Collections</h4>
      </div>
    {% if !settings.read_only %}
        <form class="form-inline" method="POST" style="float: right;">
          <div class="input-group">
            <input class="form-control" type="text" id="collection" name="collection" placeholder="Collection Name" title="Collection Name">
            <span class="input-group-btn">
              <button type="submit" class="btn btn-primary pull-right">
                <span class="glyphicon glyphicon-plus"></span>
                Create collection
              </button>
            </span>
          </div><!-- /input-group -->
        </form>
    {% endif %}

  </div>
  <div class="panel-body no-padding">
    <table class="table table-bordered table-striped table-condensed no-margin">
      {% for c in colls %}
      <tr>
        <td class="col-md-2">
          <a href="{{ dbUrl }}/{{ c | url_encode }}" class="btn btn-success btn-block">
            <span class="glyphicon glyphicon-eye-open"></span><br>View
          </a>
        </td>
        {% if !settings.me_no_export %}
        <td class="col-md-1">
          <a href="{{ dbUrl }}/export/{{ c | url_encode }}" class="btn btn-warning btn-block">
            <span class="glyphicon glyphicon-floppy-save"></span><br>Export
          </a>
        </td>
        {% endif %}
        <td class="col-md-1">
          <a href="{{ dbUrl }}/expArr/{{ c | url_encode }}" class="btn btn-warning btn-block">
            <span class="glyphicon glyphicon-floppy-save"></span><br>[JSON]
          </a>
        </td>
        <td class="col-md-1">
          <a class="btn btn-warning btn-block import-file-link">
            <span class="glyphicon glyphicon-cloud-upload"></span><br>Import
          </a>
          <input class="input-hidden import-input-file" type="file" name="import-file" collection-name="{{ c | url_encode }}"/>
        </td>
        <td><h3><a href="{{ dbUrl }}/{{ c | url_encode }}">{{ c }}</a></h3></td>
        {% if !settings.read_only %}
        <td class="col-md-1">
          <form method="POST"
            action="{{ dbUrl }}/{{ c | url_encode }}"
            style="margin: 0px;"
          >
            <input type="hidden" name="_method" value="delete">
            <button type="submit" class="hidden"></button>
            <button type="button" class="btn btn-danger btn-block deleteButton" collection-name="{{ c }}">
              <span class="glyphicon glyphicon-trash"></span><br>Del
            </button>
          </form>
        </td>
        {% endif %}
      </tr>
      {% endfor %}
    </table>
  </div>
</div>

<div id="confirm-deletion" class="modal fade" role="dialog" aria-labelledby="confirmDeletionLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Delete collection</h4>
      </div>

      <div class="modal-body">
        <p>
          Be careful! You are about to delete whole <strong><span id="modal-collection-name"></span></strong> collection.
        </p>
        <p>
          <label for="confirmation-input">Type the collection name to proceed.</label>
          <input type="text" id="confirmation-input" name="confirmation-input" shouldbe="" value="" />
        </p>
      </div>

      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-danger" id="delete">Delete</button>
        <button type="button" data-dismiss="modal" class="btn">Cancel</button>
      </div>

    </div>
  </div>
</div>

{% if grids.length && settings.gridFSEnabled %}
  <h2>GridFS Buckets</h2>

<table class="table table-bordered table-striped table-condensed">
  {% for b in grids %}
  <tr>
    <td class="col-md-2">
      <a href="{{ dbUrl }}/gridFS/{{ b }}" class="btn btn-success btn-block">
        <span class="glyphicon glyphicon-eye-open"></span><br>View
      </a>
    </td>
    <td><h3><a href="{{ dbUrl }}/gridFS/{{ b }}">{{ b }}</a></h3></td>
  </tr>
  {% endfor %}
</table>
{% endif %}

{% if !settings.read_only %}
<!--div class="row">
  <div class="col-md-6">
    <h2>Create Collection</h2>
    <form class="well form-inline" method="POST">
        <div class="form-group">
          <span class="add-on">{{ dbName }} . </span>
          <input class="input-medium" type="text" id="collection" name="collection" placeholder="Collection Name" title="Collection Name">
        </div>
        <button type="submit" class="btn btn-primary pull-right">
          <span class="glyphicon glyphicon-plus"></span>
          Create collection
        </button>
    </form>
  </div>
</div-->
<!--
<div class="row">
  <div class="col-md-6">
    <h2>Create GridFS Bucket</h2>
    <form class="well form-inline" method="POST">
        <div class="form-group">
          <span class="add-on">{{ dbName }} . </span>
          <input class="input-medium" type="text" id="bucket" name="bucket" placeholder="Bucket Name" title="Bucket Name">
        </div>
        <button type="submit" class="btn btn-primary pull-right">
          <span class="glyphicon glyphicon-plus"></span>
          Create bucket
        </button>
    </form>
  </div>
</div>
 -->
{% endif %}

<div class="panel panel-default stats">
  <div class="panel-heading">
    <h4 style="font-weight: bold;">Database Stats</h4>
  </div>
  <table class="table table-bordered table-striped">
    <tr>
      <td><strong>Collections (incl. system.namespaces)</strong></td>
      <td>{{ stats.collections }}</td>
    </tr>
    <tr>
      <td><strong>Data Size</strong></td>
      <td>{{ stats.dataSize }}</td>
    </tr>
    <tr>
      <td><strong>Storage Size</strong></td>
      <td>{{ stats.storageSize }}</td>
    </tr>
    {% if stats.fileSize %}
      <tr>
      <td><strong>File Size (on disk)</strong></td>
      <td>{{ stats.fileSize }}</td>
      </tr>
    {% endif %}
    {% if stats.avgObjSize %}
      <tr>
      <td><strong>Avg Obj Size #</strong></td>
      <td>{{ stats.avgObjSize }}</td>
      </tr>
    {% endif %}
    {% if stats.objects %}
      <tr>
      <td><strong>Objects #</strong></td>
      <td>{{ stats.objects }}</td>
      </tr>
    {% endif %}
    {% if stats.numExtents %}
      <tr>
      <td><strong>Extents #</strong></td>
      <td>{{ stats.numExtents }}</td>
      </tr>
    {% endif %}
    {% if stats.extentFreeListNum %}
      <tr>
      <td><strong>Extents Free List</strong></td>
      <td>{{ stats.extentFreeListNum }}</td>
      </tr>
    {% endif %}
    {% if stats.indexes %}
      <tr>
      <td><strong>Indexes #</strong></td>
      <td>{{ stats.indexes }}</td>
      </tr>
    {% endif %}
    {% if stats.indexSize %}
      <tr>
      <td><strong>Index Size</strong></td>
      <td>{{ stats.indexSize }}</td>
      </tr>
    {% endif %}
    {% if stats.dataFileVersion %}
      <tr>
      <td><strong>Data File Version</strong></td>
      <td>{{ stats.dataFileVersion }}</td>
      </tr>
    {% endif %}
  </table>
</div>

{% endblock %}

{% block scripts %}
{% if !settings.read_only %}
<script src="{{ baseHref }}{{ assets.database.js }}"></script>
{% endif %}
{% endblock %}
